package com.ruoyi.slope.ai.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.slope.dataFile.domain.SlopeDataFile;
import com.ruoyi.slope.dataFile.service.ISlopeDataFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.slope.ai.domain.SlopeAiAlertRuleConfig;
import com.ruoyi.slope.ai.service.ISlopeAiAlertRuleConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预警规则配置Controller
 * 
 * @author ruoyi
 * @date 2025-09-05
 */
@RestController
@RequestMapping("/ai/ruleConfig")
public class SlopeAiAlertRuleConfigController extends BaseController
{
    @Autowired
    private ISlopeDataFileService slopeDataFileService;
    @Autowired
    private ISlopeAiAlertRuleConfigService slopeAiAlertRuleConfigService;

    /**
     * 查询预警规则配置列表
     */
    @PreAuthorize("@ss.hasPermi('ai:ruleConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlopeAiAlertRuleConfig slopeAiAlertRuleConfig)
    {
        startPage();
        List<SlopeAiAlertRuleConfig> list = slopeAiAlertRuleConfigService.selectSlopeAiAlertRuleConfigList(slopeAiAlertRuleConfig);
        return getDataTable(list);
    }

    /**
     * 导出预警规则配置列表
     */
    @PreAuthorize("@ss.hasPermi('ai:ruleConfig:export')")
    @Log(title = "预警规则配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlopeAiAlertRuleConfig slopeAiAlertRuleConfig)
    {
        List<SlopeAiAlertRuleConfig> list = slopeAiAlertRuleConfigService.selectSlopeAiAlertRuleConfigList(slopeAiAlertRuleConfig);
        ExcelUtil<SlopeAiAlertRuleConfig> util = new ExcelUtil<SlopeAiAlertRuleConfig>(SlopeAiAlertRuleConfig.class);
        String path = util.exportExcel(response, list, "预警规则配置数据");
        SlopeDataFile slopeDataFile = new SlopeDataFile();
        slopeDataFile.setFileName(path);
        slopeDataFileService.insertSlopeDataFile(slopeDataFile);
    }

    /**
     * 获取预警规则配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('ai:ruleConfig:query')")
    @GetMapping(value = "/{ruleId}")
    public AjaxResult getInfo(@PathVariable("ruleId") String ruleId)
    {
        return success(slopeAiAlertRuleConfigService.selectSlopeAiAlertRuleConfigByRuleId(ruleId));
    }

    /**
     * 新增预警规则配置
     */
    @PreAuthorize("@ss.hasPermi('ai:ruleConfig:add')")
    @Log(title = "预警规则配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlopeAiAlertRuleConfig slopeAiAlertRuleConfig)
    {
        return toAjax(slopeAiAlertRuleConfigService.insertSlopeAiAlertRuleConfig(slopeAiAlertRuleConfig));
    }

    /**
     * 修改预警规则配置
     */
    @PreAuthorize("@ss.hasPermi('ai:ruleConfig:edit')")
    @Log(title = "预警规则配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlopeAiAlertRuleConfig slopeAiAlertRuleConfig)
    {
        return toAjax(slopeAiAlertRuleConfigService.updateSlopeAiAlertRuleConfig(slopeAiAlertRuleConfig));
    }

    /**
     * 删除预警规则配置
     */
    @PreAuthorize("@ss.hasPermi('ai:ruleConfig:remove')")
    @Log(title = "预警规则配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable String[] ruleIds)
    {
        return toAjax(slopeAiAlertRuleConfigService.deleteSlopeAiAlertRuleConfigByRuleIds(ruleIds));
    }
}
